from django.db import models


# Create your models here.

class adminis(models.Model):
    """ 管理员 """
    username = models.CharField(verbose_name="用户名", max_length=32)
    password = models.CharField(verbose_name="密码", max_length=64)

    def __str__(self):
        return self.username


class department(models.Model):
    """ 部门表 """
    title = models.CharField(max_length=9)

    def __str__(self):
        return self.title


class userinfo(models.Model):
    """ 员工表 """
    name = models.CharField(verbose_name="姓名", max_length=16)
    password = models.CharField(verbose_name="密码", max_length=64)
    age = models.IntegerField(verbose_name="年龄")
    # 默认是0，2位小数点
    account = models.DecimalField(verbose_name="余额", max_digits=10, decimal_places=2, default=0)
    create_time = models.DateTimeField(verbose_name="入职时间", )

    # 1.部门id 关联部门id 无约束
    #   depart_did = models.BigIntegerField(validators='部门ID',)
    #   有约束 关联部门id 有约束   -to与那张表关联，-to_fields与表中的那一列关联
    # 2.django 自动写的depart,在数据库生成数据列 depart_id
    # 3.部门表被删除
    #     3.1 级联删除
    #     depart = models.ForeignKey(to='Department', to_fields='id',on_delete=models.CASCADE)
    #     3.2 置空
    #     depart = models.ForeignKey(to='Department', to_fields='id',on_delete=models.CASCADE,null=True,blank=True)
    #

    depart = models.ForeignKey(verbose_name="部门", to='department', to_field='id', on_delete=models.CASCADE, null=True,
                               blank=True)

    gender_choices = (
        (1, "男"),
        (2, "女")
    )
    gender = models.SmallIntegerField(choices=gender_choices, verbose_name="性别", default=1)


class prettynum(models.Model):
    """靓号表"""
    mobile = models.CharField(verbose_name="手机号", max_length=11)
    # 想要允许为空， null = Ture , blank = True
    price = models.IntegerField(verbose_name="价格", default=0)
    level_choices = (
        (1, "1级"),
        (2, "2级"),
        (3, "3级"),
        (4, "4级"),
        (5, "5级"),
    )
    level = models.SmallIntegerField(verbose_name="级别", choices=level_choices, default=1)

    status_choices = (
        (1, "已占用"),
        (2, "未使用"),
    )
    status = models.SmallIntegerField(verbose_name="状态", choices=status_choices, default=2)


class task(models.Model):
    """ 任务 """
    level_choices = (
        (1, "紧急"),
        (2, "重要"),
        (3, "临时"),
    )

    level = models.SmallIntegerField(verbose_name="级别", choices=level_choices, default=1)
    titlet = models.CharField(verbose_name="标题", max_length=64)
    detail = models.TextField(verbose_name="详细信息")
    user = models.ForeignKey(verbose_name="负责人", to="adminis", to_field='id', on_delete=models.CASCADE)


class order(models.Model):
    """ 订单 """
    oid = models.CharField(verbose_name="订单号", max_length=64)
    titleo = models.CharField(verbose_name="名称", max_length=32)
    price = models.IntegerField(verbose_name="价格")
    status_choices = {
        (1, "待支付"),
        (2, "已支付")
    }
    status = models.SmallIntegerField(verbose_name="状态", choices=status_choices, default=1)
    admin = models.ForeignKey(verbose_name="管理员", to="adminis", on_delete=models.CASCADE)
